package com.totcy.atom.presenter;

import android.content.Context;

import com.totcy.atom.bean.DailySentenceCiBa;
import com.totcy.atom.model.DailySentenceModel;
import com.totcy.atom.presenter.contract.DailySentenceContract;
import com.totcy.baselibrary.base.mvpbase.BasePresenterImpl;

/**
 * description : 每日一句presenter
 *
 * @author : Totcy
 * @date : 2017/12/7 17:10
 * @update : 2017/12/7
 */

public class DailySentencePresenter extends BasePresenterImpl<DailySentenceContract.View, DailySentenceContract.Model> implements DailySentenceContract.Presenter {

    public DailySentencePresenter(Context context) {
        super(context);
    }

    @Override
    public DailySentenceContract.Model attachModel() {
        return new DailySentenceModel(mContext);
    }

    /**
     * Presenter 调用 model 获取数据
     */
    @Override
    public void getDailySentence() {
        if (isModelAttached()) {
            getModel().getDailySentence(new DailySentenceContract.Model.DataCallback() {
                @Override
                public void onDailySentenceCiBa(DailySentenceCiBa bean) {
                    if (isViewAttached()) {
                        getView().onDailySentenceCiBa(bean);
                    }
                }

                @Override
                public void onDataNotAvailable(int code, String message) {
                    if (isViewAttached()) {
                        getView().onDataFail(code, message);
                    }
                }
            });
        }
    }
}
